package org.crazyit.activiti_d2._10_NativeQueryTest;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.Group;

import java.util.List;

public class NativeQueryTest {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到身份服务组件实例
        IdentityService identityService = engine.getIdentityService();

        //3. 使用原生SQL 查询全部数据
        List<Group> groups1 = identityService.createNativeGroupQuery().sql("select * from ACT_ID_GROUP").list();
        System.out.println("查询全部数据:" + groups1.size());

        //4. 使用原生SQL 按条件查询, 并设置参数, 只查到一条数据
        List<Group> groups2 = identityService.createNativeGroupQuery().sql("select * from ACT_ID_GROUP where NAME_ = 'GroupC'").list();
        System.out.println("按条件查询:" + groups2.get(0).getName());

        //5. 使用parameter 方法 设置查询参数
        List<Group> groups3 = identityService.createNativeGroupQuery().sql("select * from ACT_ID_GROUP where NAME_ = #{name}").parameter("name", "GroupD").list();
        System.out.println("使用parameter 方法按条件查询: " + groups3.get(0).getName());

    }

}
